package cn.iocoder.yudao.module.contract.service.orderContract;

import cn.hutool.core.date.DateUtil;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
import cn.iocoder.yudao.framework.common.util.number.MoneyUtil;
import cn.iocoder.yudao.module.contract.dal.dataobject.client.ClientDO;
import cn.iocoder.yudao.module.contract.dal.dataobject.company.CompanyDO;
import cn.iocoder.yudao.module.contract.dal.dataobject.contractTemplate.ContractTemplateDO;
import cn.iocoder.yudao.module.contract.dal.dataobject.frameworkAgreement.FrameworkAgreementDO;
import cn.iocoder.yudao.module.contract.dal.dataobject.material.MaterialDO;
import cn.iocoder.yudao.module.contract.dal.dataobject.order.OrderDO;
import cn.iocoder.yudao.module.contract.dal.dataobject.order.OrderDetailsDO;
import cn.iocoder.yudao.module.contract.dal.dataobject.orderContract.vo.CompanyOrderContractVO;
import cn.iocoder.yudao.module.contract.dal.mysql.material.MaterialMapper;
import cn.iocoder.yudao.module.contract.enums.OrderFreezeStatusEnum;
import cn.iocoder.yudao.module.contract.service.client.ClientService;
import cn.iocoder.yudao.module.contract.service.company.CompanyService;
import cn.iocoder.yudao.module.contract.service.contractTemplate.ContractTemplateService;
import cn.iocoder.yudao.module.contract.service.frameworkAgreement.FrameworkAgreementService;
import cn.iocoder.yudao.module.contract.service.material.MaterialService;
import cn.iocoder.yudao.module.contract.service.order.OrderService;
import cn.iocoder.yudao.module.contract.utils.HtmlToFileConverter;
import cn.iocoder.yudao.module.contract.utils.StringUtils;
import cn.iocoder.yudao.module.contract.webservice.ContractWebService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.math.BigDecimal;
import java.util.*;

import cn.iocoder.yudao.module.contract.controller.admin.orderContract.vo.*;
import cn.iocoder.yudao.module.contract.dal.dataobject.orderContract.OrderContractDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.contract.dal.mysql.orderContract.OrderContractMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.contract.enums.ErrorCodeConstants.*;

/**
 * 订单合同 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
@Slf4j
public class OrderContractServiceImpl extends ServiceImpl<OrderContractMapper, OrderContractDO> implements OrderContractService {

    @Resource
    private OrderContractMapper orderContractMapper;
    @Resource
    private OrderService orderService;
    @Resource
    private CompanyService companyService;
    @Resource
    private ClientService clientService;
    @Resource
    private FrameworkAgreementService frameworkAgreementService;
    @Resource
    private HtmlToFileConverter htmlToFileConverter;
    @Resource
    private ContractTemplateService templateService;
    @Resource
    private ContractWebService contractWebService;
    @Resource
    private MaterialMapper materialtMapper;

    @Override
    @Async
    public void createOrderContract(OrderDO orderDO) {
        //orderStatus订单状态  0已创建 1已同步 2已生成合同 3作废  4已回收
        // 插入
        OrderContractDO orderContractDO = getOne(Wrappers.<OrderContractDO>lambdaQuery().eq(OrderContractDO::getOrderId,orderDO.getId()),false);
        OrderContractDO orderContract = new OrderContractDO();
        if(orderContractDO!=null){
            orderContract.setId(orderContractDO.getId());
        }

        //默认获取销售模板
        ContractTemplateDO contractTemplateDO = templateService.getOne(Wrappers.<ContractTemplateDO>lambdaQuery().eq(ContractTemplateDO::getContractTypeCode,orderDO.getHtdymb()),false);
        if(contractTemplateDO!=null){
            orderContract.setContractTypeCode(contractTemplateDO.getContractTypeCode());
            orderContract.setContractTypeName(contractTemplateDO.getContractTypeName());
            orderContract.setContractTemplateId(contractTemplateDO.getId());
            orderContract.setContractTemplateName(contractTemplateDO.getContractName());
        }
        orderContract.setOrderId(orderDO.getId());
        saveOrUpdate(orderContract);
        orderContract.setOrderStatus("1");
        contractWebService.pushOrderStatus(orderDO.getVbeln(),"1",orderContract);
        updateById(orderContract);
        generateContractFile(orderContract);
        if("1".equals(orderContract.getStatus()) && !"2".equals(orderContract.getOrderStatus())){
            orderContract.setOrderStatus("2");
            contractWebService.pushOrderStatus(orderDO.getVbeln(),"2",orderContract);
        }
        OrderDO order = new OrderDO();
        order.setId(orderDO.getId());
        order.setContractId(String.valueOf(orderContract.getId()));
        order.setContractNo("");
        order.setStatus("1");
        orderService.updateById(order);
        updateById(orderContract);
    }

    @Override
    public void updateOrderContract(OrderContractSaveReqVO updateReqVO) {
        // 校验存在
        validateOrderContractExists(updateReqVO.getId());
        // 更新
        OrderContractDO updateObj = BeanUtils.toBean(updateReqVO, OrderContractDO.class);
        orderContractMapper.updateById(updateObj);
    }

    @Override
    public void deleteOrderContract(Long id) {
        // 校验存在
        validateOrderContractExists(id);
        // 删除
        orderContractMapper.deleteById(id);
    }

    private void validateOrderContractExists(Long id) {
        if (orderContractMapper.selectById(id) == null) {
            throw exception(ORDER_CONTRACT_NOT_EXISTS);
        }
    }

    @Override
    public OrderContractDO getOrderContract(Long id) {
        return orderContractMapper.selectById(id);
    }

    @Override
    public PageResult<OrderContractPageRespVO> getOrderContractPage(OrderContractPageReqVO pageReqVO) {
        return orderContractMapper.selectPage(pageReqVO);
    }

    @Override
    public void fileUpload(OrderContractSaveReqVO updateReqVO) {
        OrderContractDO updateObj = BeanUtils.toBean(updateReqVO, OrderContractDO.class);
        if(StringUtils.isBlank(updateObj.getFileIds())){
            throw exception("请上传附件");
        }
        orderContractMapper.updateById(updateObj);
    }

    @Override
    public void generateContractFile(OrderContractDO orderContractDO) {
        try{
            OrderDO orderDO = orderService.getOrder(orderContractDO.getOrderId());
            if(orderDO==null){
                throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"订单不存在");
            }

            ContractTemplateDO contractTemplate = templateService.getOne(Wrappers.<ContractTemplateDO>lambdaQuery().eq(ContractTemplateDO::getContractTypeCode,orderDO.getHtdymb()).eq(ContractTemplateDO::getClientCode,orderDO.getKunnr()),false);
            if(contractTemplate==null){
                contractTemplate = templateService.getOne(Wrappers.<ContractTemplateDO>lambdaQuery().eq(ContractTemplateDO::getContractTypeCode,orderDO.getHtdymb()).isNull(ContractTemplateDO::getClientId),false);
                if(contractTemplate ==null){
                    throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"合同模板不存在");
                }
            }

            orderContractDO.setContractTypeCode(contractTemplate.getContractTypeCode());
            orderContractDO.setContractTypeName(contractTemplate.getContractTypeName());
            orderContractDO.setContractTemplateId(contractTemplate.getId());
            orderContractDO.setContractTemplateName(contractTemplate.getContractName());
            List<OrderDetailsDO> orderDeatils =  orderService.getOrderDetailsListByOrderId(orderContractDO.getOrderId());
            CompanyDO companyDO = companyService.getOne(Wrappers.<CompanyDO>lambdaQuery().eq(CompanyDO::getCompanyCode,orderDO.getBukrs()),false);
            if(companyDO==null){
                throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"未找到公司代码"+orderDO.getBukrs()+"的公司信息");
            }
            ClientDO clientDO = clientService.getOne(Wrappers.<ClientDO>lambdaQuery().eq(ClientDO::getClientCode,orderDO.getKunnr()),false);
            if(clientDO==null){
                throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"未找到售达方"+orderDO.getKunnr()+"的客户信息");
            }
            String contractNo = "";
            Long frameworkAgreementId = null;
            if(orderContractDO.getContractTypeCode().equals("Y3")){
                FrameworkAgreementDO frameworkAgreementDO = frameworkAgreementService.getOne(Wrappers.<FrameworkAgreementDO>lambdaQuery()
                        .eq(FrameworkAgreementDO::getClientName,clientDO.getClientName())
                        .ge(FrameworkAgreementDO::getAgreementEndDate,orderDO.getAudat())
                        .le(FrameworkAgreementDO::getAgreementStartDate,orderDO.getAudat()),false);
                if(frameworkAgreementDO!=null){
                    contractNo = frameworkAgreementDO.getContractNo();
                    frameworkAgreementId = frameworkAgreementDO.getId();
                }else{
                    throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"当前报价单未找到框架协议");
                }
            }
            String htmlContent = contractTemplate.getContractContent();
            htmlContent = htmlInit(htmlContent);
            Map<String,Object> param = buildContractParam(orderContractDO,orderDO,orderDeatils,companyDO,clientDO,contractNo);
            htmlContent = HtmlToFileConverter.authHtmlToPdf(htmlContent, param);
            BigDecimal totalMoney = BigDecimal.ZERO;
            if(orderDeatils.size()>0){
                totalMoney = orderDeatils.stream()
                        .filter(map -> map.getDdje() != null) // 过滤掉null值
                        .map(map -> {return new BigDecimal(map.getDdje()); // 转换为BigDecimal
                        })
                        .reduce(BigDecimal.ZERO, BigDecimal::add); // 累加
            }
            String fileUrl = htmlToFileConverter.htmlToWord(htmlContent,"contract/"+orderDO.getVbeln(),"ht-");
            orderContractDO.setTotalMoney(totalMoney.toString());
            orderContractDO.setContractHtml(htmlContent);
            orderContractDO.setContractFileUrl(fileUrl);
            orderContractDO.setStatus("1");
            orderContractDO.setAbnormalCause("");
            orderContractDO.setFrameworkAgreementId(frameworkAgreementId);
        }catch (ServiceException e){
            orderContractDO.setStatus("0");
            orderContractDO.setAbnormalCause("合同生成失败："+e.getMessage());
            log.error("合同生成失败-{}:",orderContractDO.getId(),e);
        }catch (Exception e){
            orderContractDO.setStatus("0");
            orderContractDO.setAbnormalCause("合同生成失败：系统异常");
            log.error("合同生成失败-{}:",orderContractDO.getId(),e);
        }
    }

    /**
     * 处理富文本html
     * @param htmlContent
     * @return
     */
    private String htmlInit(String htmlContent) {
        htmlContent= htmlContent.replaceAll("\\$\\{序号}","\\$\\{orderInfo.序号}");
        htmlContent= htmlContent.replaceAll("\\$\\{行项目}","\\$\\{orderInfo.行项目}");
        htmlContent= htmlContent.replaceAll("\\$\\{产品组}","\\$\\{orderInfo.产品组}");
        htmlContent= htmlContent.replaceAll("\\$\\{产品组描述}","\\$\\{orderInfo.产品组描述}");
        htmlContent= htmlContent.replaceAll("\\$\\{产品规格}","\\$\\{orderInfo.产品规格}");
        htmlContent= htmlContent.replaceAll("\\$\\{物料号}","\\$\\{orderInfo.物料号}");
        htmlContent= htmlContent.replaceAll("\\$\\{物料描述}","\\$\\{orderInfo.物料描述}");
        htmlContent= htmlContent.replaceAll("\\$\\{旧物料号}","\\$\\{orderInfo.旧物料号}");
        htmlContent= htmlContent.replaceAll("\\$\\{订单数量}","\\$\\{orderInfo.订单数量}");
        htmlContent= htmlContent.replaceAll("\\$\\{成交单价}","\\$\\{orderInfo.成交单价}");
        htmlContent= htmlContent.replaceAll("\\$\\{加工费}","\\$\\{orderInfo.加工费}");
        htmlContent= htmlContent.replaceAll("\\$\\{订单金额}","\\$\\{orderInfo.订单金额}");
        htmlContent= htmlContent.replaceAll("\\$\\{等级}","\\$\\{orderInfo.等级}");
        htmlContent= htmlContent.replaceAll("\\$\\{备注}","\\$\\{orderInfo.备注}");
        htmlContent= htmlContent.replaceAll("\\$\\{产品质量}","\\$\\{orderInfo.产品质量}");
//        htmlContent= htmlContent.replaceAll("\\$\\{再生产品备注}","\\$\\{orderInfo.再生产品备注}");
        htmlContent= htmlContent.replaceAll("\\$\\{不含税总金额}","\\$\\{orderInfo.不含税总金额}");
        htmlContent= htmlContent.replaceAll("\\$\\{原销售订单}","\\$\\{orderInfo.原销售订单}");
        htmlContent= htmlContent.replaceAll("\\$\\{原项目}","\\$\\{orderInfo.原项目}");
        htmlContent= htmlContent.replaceAll("\\$\\{拒绝原因}","\\$\\{orderInfo.拒绝原因}");

//        htmlContent = addWatermark(htmlContent);
        Document doc = Jsoup.parse(htmlContent);
        Elements tdElements =  doc.select("td");
        for (Element cell : tdElements) {
            String text = cell.text(); // 获取td元素及其所有子元素的文本内容
            if (text.startsWith("${orderInfo")) {
                Element tr = cell.parent(); // 获取单元格的父元素
                if (tr.tagName().equals("tr")) { // 确保父元素是tr
                    Element trr = tr.parent(); // 获取单元格的父元素
                    if(!trr.tagName().equals("list")) {
                        // 创建<#list></#list>元素
                        tr.wrap("<list>");
                    }
                }
            }
        }

        htmlContent = doc.html();
        htmlContent = htmlContent.replaceAll("<list>","<#list orderDetails as orderInfo>");
        htmlContent = htmlContent.replaceAll("</list>","</#list>");
        return htmlContent;
    }

    /**
     * 构建合同变量参数
     * @return
     */
    private Map<String,Object> buildContractParam(OrderContractDO orderContractDO,OrderDO orderDO,List<OrderDetailsDO> orderDeatils,CompanyDO companyDO,ClientDO clientDO,String contractNo){

        Map<String,Object> param = new HashMap<>();
        //订单信息
        param.put("凭证日期",StringUtils.nvl(orderDO.getAudat(), ""));
        param.put("销售凭证",StringUtils.nvl(orderDO.getVbeln(), ""));
        param.put("销售凭证类型",StringUtils.nvl(orderDO.getAuart(), ""));
        param.put("凭证类型描述",StringUtils.nvl(orderDO.getAuartt(), ""));
        param.put("销售组织",StringUtils.nvl(orderDO.getVkorg(), ""));
        param.put("公司代码",StringUtils.nvl(orderDO.getBukrs(), ""));
        param.put("公司名称",StringUtils.nvl(orderDO.getButxt(), ""));
        param.put("售达方",StringUtils.nvl(orderDO.getKunnr(), ""));
        param.put("售达方描述",StringUtils.nvl(orderDO.getKname(), ""));
        param.put("销售部门",StringUtils.nvl(orderDO.getVkbur(), ""));
        param.put("部门描述",StringUtils.nvl(orderDO.getVkburt(), ""));
        param.put("销售组",StringUtils.nvl(orderDO.getVkgrp(), ""));
        param.put("组描述",StringUtils.nvl(orderDO.getVkgrpt(), ""));
        param.put("业务员",StringUtils.nvl(orderDO.getYwy(), ""));
        param.put("业务员名称",StringUtils.nvl(orderDO.getYwyt(), ""));
        param.put("装运条件",StringUtils.nvl(orderDO.getVsbed(), ""));
        param.put("合同管控类型",StringUtils.nvl(orderDO.getZzhtgklx(), ""));
        param.put("合同管控类型描述",StringUtils.nvl(orderDO.getZzhtgklxms(), ""));
        param.put("抬头合同打印备注",StringUtils.nvl(orderDO.getZzhthbz(), ""));
        param.put("送货地址",StringUtils.nvl((StringUtils.isBlank(orderDO.getZzshdz())?clientDO.getStreet():orderDO.getZzshdz()), ""));
        param.put("付款条件",StringUtils.nvl(orderDO.getZterm(), ""));
        param.put("付款条件解释",StringUtils.nvl(orderDO.getZtermt(), ""));
        param.put("交货冻结",StringUtils.nvl(orderDO.getLifsk(), ""));
        param.put("信用期",StringUtils.nvl(orderDO.getZmonth(), ""));
        param.put("订单原因",StringUtils.nvl(orderDO.getAugru(), ""));
        param.put("订单原因解释",StringUtils.nvl(orderDO.getAugrut(), ""));
        param.put("运输方式费用负担",StringUtils.nvl(orderDO.getYffd(), ""));
        param.put("付款方式",StringUtils.nvl(orderDO.getFkfs(), ""));
        param.put("产品质量汇总",StringUtils.nvl(orderDO.getCpzl(), ""));
        param.put("凭证货币", StringUtils.nvl(orderDO.getWaerk(), ""));
        //产品信息
        List<Map<String,Object>> details = new ArrayList<>();
        BigDecimal quantityTotal= BigDecimal.ZERO;
        BigDecimal amountSum = BigDecimal.ZERO;
        BigDecimal noTaxAmountSum = BigDecimal.ZERO;
        String rebirthRemark = "";

        for(int i=0;i<orderDeatils.size();i++){
            OrderDetailsDO orderDetailsDO = orderDeatils.get(i);
            if(StringUtils.isNotBlank(orderDetailsDO.getZzvbeln())){
                continue;
            }
            MaterialDO materialDO = null;
            if(StringUtils.isNotBlank(orderDetailsDO.getMatnr())){
                materialDO = materialtMapper.selectOne(new LambdaQueryWrapper<MaterialDO>().eq(MaterialDO::getMatnr,orderDetailsDO.getMatnr()),false);
            }
            Map<String,Object> data = new HashMap<>();
            data.put("序号",i+1);
            data.put("行项目",StringUtils.nvl(orderDetailsDO.getPosnr(),""));
            data.put("产品组",StringUtils.nvl(orderDetailsDO.getSpart(),""));
            data.put("产品组描述",StringUtils.nvl(orderDetailsDO.getSpartt(),""));
            if(materialDO==null){
                data.put("产品规格",StringUtils.nvl(orderDetailsDO.getZzcpgg(),""));
            }else{
                data.put("产品规格",StringUtils.nvl(materialDO.getZzcpgg(),""));
            }
            data.put("物料号",StringUtils.nvl(orderDetailsDO.getMatnr(),""));
            data.put("物料描述",StringUtils.nvl(orderDetailsDO.getArktx(),""));
            if(materialDO==null) {
                data.put("旧物料号",StringUtils.nvl(orderDetailsDO.getBismt(),""));
            }else{
                data.put("旧物料号",StringUtils.nvl(materialDO.getBismt(),""));
            }
            data.put("订单数量",StringUtils.nvl(MoneyUtil.toSeparator(orderDetailsDO.getKwmeng()),""));
            data.put("成交单价",StringUtils.nvl(orderDetailsDO.getCjdj(),""));
            data.put("加工费",StringUtils.nvl(orderDetailsDO.getZyp(),""));
            data.put("订单金额",StringUtils.nvl(MoneyUtil.toSeparator(orderDetailsDO.getDdje()),""));
            data.put("等级",StringUtils.nvl(orderDetailsDO.getDj(),""));
            data.put("备注",StringUtils.nvl(orderDetailsDO.getZzhtibz(),""));
            data.put("产品质量",StringUtils.nvl(orderDetailsDO.getCpzl(),""));
            data.put("不含税总金额",StringUtils.nvl(MoneyUtil.toSeparator(orderDetailsDO.getNetwr()),""));
            data.put("原销售订单",StringUtils.nvl(orderDetailsDO.getZzvbeln(),""));
            data.put("原项目",StringUtils.nvl(orderDetailsDO.getZzposnr(),""));
            data.put("拒绝原因",StringUtils.nvl(orderDetailsDO.getAbgru(),""));
            data.put("物料功能性",StringUtils.nvl(orderDetailsDO.getZzwlgnx(),""));

            if(StringUtils.isNotBlank(orderDetailsDO.getKwmeng())){
                quantityTotal = quantityTotal .add(new BigDecimal(orderDetailsDO.getKwmeng()));
            }
            if(StringUtils.isNotBlank(orderDetailsDO.getDdje())){
                amountSum = amountSum.add(new BigDecimal(orderDetailsDO.getDdje()));
            }
            if(StringUtils.isNotBlank(orderDetailsDO.getNetwr())){
                noTaxAmountSum = noTaxAmountSum.add(new BigDecimal(orderDetailsDO.getNetwr()));
            }
            if(StringUtils.isNotBlank(orderDetailsDO.getZscpbz())){
                rebirthRemark = orderDetailsDO.getZscpbz();
            }
            details.add(data);
        }
        param.put("orderDetails",details);

        //产品合计
        param.put("再生产品备注",rebirthRemark);
        param.put("数量合计",MoneyUtil.toSeparator(quantityTotal.toString()));
        param.put("不含税总金额合计",StringUtils.nvl(MoneyUtil.toSeparator(noTaxAmountSum.toString()), ""));
        param.put("订单金额合计",StringUtils.nvl(MoneyUtil.toSeparator(amountSum.toString()), ""));
        param.put("合计金额大写",StringUtils.nvl(MoneyUtil.toChinese(String.valueOf(amountSum)), ""));
        //其他
        param.put("报价单归属合同号",StringUtils.nvl(contractNo, ""));
        param.put("补充协议编号","BCXY"+orderDO.getVbeln());
        param.put("生成日期", DateUtil.format(new Date(),"yyyy年MM月dd日"));
        //公司信息（乙方）
        param.put("供方单位名称",StringUtils.nvl(companyDO.getCompanyName(), ""));
        param.put("供方单位地址",StringUtils.nvl(companyDO.getAddress(), ""));
        param.put("供方法定代表",StringUtils.nvl(companyDO.getLegalPerson(), ""));
        param.put("供方电话",StringUtils.nvl(companyDO.getPhone(), ""));
        param.put("供方传真",StringUtils.nvl(companyDO.getFaxes(), ""));
        param.put("供方开户银行",StringUtils.nvl(companyDO.getBankName(), ""));
        param.put("供方账号",StringUtils.nvl(companyDO.getBankAccount(), ""));
        param.put("供方税号",StringUtils.nvl(companyDO.getTaxNumber(), ""));
        param.put("签订地点",StringUtils.nvl(companyDO.getSigningAddress(), ""));
        //客户信息（甲方）

        param.put("客户名称",StringUtils.nvl(clientDO.getClientName(), ""));
        param.put("客户简称",StringUtils.nvl(clientDO.getCalledForShort(), ""));
        param.put("客户电话",StringUtils.nvl(clientDO.getPhone(), ""));
        param.put("客户传真",StringUtils.nvl(clientDO.getFaxes(), ""));
        param.put("客户街道",StringUtils.nvl(clientDO.getStreet(), ""));
        param.put("客户法定代表",StringUtils.nvl(clientDO.getLegalPerson(), ""));
        param.put("客户委托代表",StringUtils.nvl(clientDO.getProxy(), ""));
        param.put("客户开户银行",StringUtils.nvl(clientDO.getBankName(), ""));
        param.put("客户开户账号",StringUtils.nvl(clientDO.getBankAccount(), ""));
        param.put("客户QQ",StringUtils.nvl(clientDO.getQqNumber(), ""));
        param.put("客户微信",StringUtils.nvl(clientDO.getWeChatNumber(), ""));
        param.put("客户收票地址",StringUtils.nvl(clientDO.getCollectionAddress(), ""));
        param.put("客户接收人姓名",StringUtils.nvl(clientDO.getReceiverName(), ""));
        param.put("客户接收人职务",StringUtils.nvl(clientDO.getReceiverDuty(), ""));
        param.put("客户接收人电话",StringUtils.nvl(clientDO.getReceiverPhone(), ""));
        param.put("街道2", StringUtils.nvl(clientDO.getStrSuppl1(), ""));
        param.put("街道3", StringUtils.nvl(clientDO.getStrSuppl2(), ""));
        return param;
    }

    @Override
    public boolean orderContractFreeze(long id) {
        OrderContractDO orderContractDO = new OrderContractDO();
        orderContractDO.setId(id);
        orderContractDO.setOrderFreezeStatus(OrderFreezeStatusEnum.FROZEN.getStatus());
        return updateById(orderContractDO);
    }

    @Override
    public boolean orderContractRelease(long id) {
        OrderContractDO orderContractDO = new OrderContractDO();
        orderContractDO.setId(id);
        orderContractDO.setOrderFreezeStatus(OrderFreezeStatusEnum.RELEASE.getStatus());
        return updateById(orderContractDO);
    }

    @Override
    public List<OrderContractDO> listUnUploadContractFile() {
        return orderContractMapper.listUnUploadContractFile();
    }

    @Override
    public List<CompanyOrderContractVO> listCompanyOrderContract(String clientCode,String intervalDate, List<Long> excludeContractIds) {
        return orderContractMapper.listCompanyOrderContract(clientCode,intervalDate,excludeContractIds);
    }
}